<template>
  <div>
    <h2>登录</h2>
    <table class="table table-bordered">
      <tr>
        <td>账号</td>
        <td>
          <input type="text" v-model="sdata.U_Name" />
        </td>
      </tr>
      <tr>
        <td>密码</td>
        <td>
          <input type="password" v-model="sdata.U_Pwd" />
        </td>
      </tr>
      <tr>
        <td></td>
        <td><input type="button" value="登录" @click="add" /></td>
      </tr>
    </table>
  </div>
</template>

<script setup lang="ts">
import { reactive, toRefs, onMounted } from 'vue';
import axios from 'axios';
import { useRoute, useRouter } from 'vue-router';
const router = useRouter();
const route = useRoute();

import { useStore } from '../../src/store/user';
const store = useStore();

let data = reactive({
  sdata: {
    U_Name: '',
    U_Pwd: ''
  }
});

const { sdata } = toRefs(data);

const add = () => {
  axios({
    url: 'http://localhost:52089/api/User/Login',
    method: 'get',
    params: sdata.value
  }).then((res) => {
    console.log(res);
    if (res.data.data == -1) {
      alert('不是普通用户');
      return;
    } else if (res.data.data == -10) {
      alert('没有此账户');
      return;
    } else {
      alert('普通用户登录成功');
      store.userInfo = res.data.data[0];
      router.push('/show');
    }
  });
};
</script>

<style scoped></style>
